﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interactivity;

namespace Client.Framework.View
{
    /// <summary>
    /// Author: Leil
    /// Description: PasswordBoxBehavior
    /// CreateTime: 2020/6/1 18:03:09
    /// </summary>
    public class PasswordBoxBehavior : Behavior<PasswordBox>
    {
        protected override void OnAttached()
        {
            base.OnAttached();
            AssociatedObject.PasswordChanged += OnPasswordChanged;
        }



        protected override void OnDetaching()
        {
            base.OnDetaching();
            AssociatedObject.PasswordChanged -= OnPasswordChanged;
        }



        private static void OnPasswordChanged(object sender, RoutedEventArgs e)
        {
            if (sender is PasswordBox box)
            {
                string password = PasswordBoxHelper.GetPassword(box);
                if (box.Password != password)
                {
                    PasswordBoxHelper.SetPassword(box, box.Password);
                }
            }
            
        }




    }
}
